#include "MainWindow.h"
#include "ui_MainWindow.h"

#include "Cube.h"
#include "Cylinder.h"
#include "Sierpinski.h"
#include "SierpinskiPontos.h"
#include "Eixos.h"

float circunferencia_X(float x_zero, float raio, float angulo)
{
    return(x_zero + raio * cos(angulo*M_PI/180));
}

float circunferencia_Y(float y_zero, float raio, float angulo)
{
    return(y_zero + raio * sin(angulo*M_PI/180));
}

void triangulo_gerar_vertices(float mediana, Point2f G, Point2f *vertices)
{
    float angulo = 90;
    for (int i=0 ; i<3 ; i++)
    {
        vertices[i] = (Point2f( circunferencia_X(G.x,mediana,angulo) , circunferencia_Y(G.y,mediana,angulo) ));
        angulo+=120;
        cout<<"vertice["<<(i+1)<<"]: ("<<vertices[i].x<<","<<vertices[i].y<<")"<<endl;
    }
}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Alterar o zoom e as cores ao iniciar:
    ui->glWidget->setZoom(1.5);
    ui->glWidget->setRedColor(ui->corVermelha->value());
    ui->glWidget->setGreenColor(ui->corVerde->value());
    ui->glWidget->setBlueColor(ui->corAzul->value());

//    ui->glWidget->addDrawble(new Cylinder(2.0, 1.0, 10));
//    ui->glWidget->addDrawble(new Cube(1.0));
//    ui->glWidget->addDrawble(new Eixos(2.0));

    Point2f vertices[3];

    triangulo_gerar_vertices(1.0,Point2f(-0.7,-0.7),vertices);
    ui->glWidget->addDrawble(
    new Sierpinski(
        vertices[0],
        vertices[1],
        vertices[2],
        8
    ));

    triangulo_gerar_vertices(1.0,Point2f(0.6,0.4),vertices);
    ui->glWidget->addDrawble(
    new SierpinskiPontos(
        vertices[0],
        vertices[1],
        vertices[2],
        10000
    ));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::rotate()
{
    cout<<"AVISO: rotate() esta desativada!"<<endl;
//    ui->glWidget->rotateX(ui->rotX->value());
//    ui->glWidget->rotateY(ui->rotY->value());
//    ui->glWidget->rotateZ(ui->rotZ->value());
//    ui->glWidget->updateGL();
}
